/**
 * @(#)RetentTaskExecTimesTimer.java 2017年11月27日
 * Copyright(C) 2017 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.timer;

import javax.annotation.Resource;

import org.jsbd.boss.service.IRetentLogService;
import org.jsbd.boss.util.CacheKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * 留存执行次数统计
 * 
 * @author <a href="mailto:xupengcheng@zhexinit.com" >徐鹏程</a>
 * @version 1.0.0
 */
@Service
public class RetentTaskExecTimesTimer extends TaskAdapterHandler {
	public static final Logger LOGGER = LoggerFactory.getLogger(RetentTaskExecTimesTimer.class);

	@Resource
	private IRetentLogService retentLogService;

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jsbd.boss.timer.TaskHandler#execute()
	 */
	@Override
	public void run() {
		long expireTime = 60;
		Object refreshTime = cacheParamManager.getParamValue(CacheKey.RETENT_EXEC_TIMER_TIME);
		if (refreshTime != null) {
			expireTime = Long.parseLong(refreshTime.toString());
		}
		if (redisClient.evalSetNx(CacheKey.RETENT_EXEC_TIMES_LOCK, expireTime)) {
			long now = System.currentTimeMillis();
			retentLogService.countRetentExecTimes();
			LOGGER.warn("留存执行次数统计 {} 秒", ((System.currentTimeMillis() - now) / 1000));
		}
	}
}
